<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>教职工离职记录</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <div class="hearder-search mb-10">
          <el-input v-model="searchForm.realname" placeholder="填写姓名" size="small" class="w-200 mr-10"></el-input>
          <el-select v-model="searchForm.role" placeholder="请选择角色" size="small" class="mr-10">
            <el-option :label="item.name" :value="item.id" v-for="(item, index) in role" :key="index"></el-option>
          </el-select>
<!--          <el-date-picker type="date"-->
<!--                          placeholder="离职时间"-->
<!--                          v-model="searchForm.end_time"-->
<!--                          :picker-options="pickerOptions1"-->
<!--                          value-format="yyyy-MM-dd"-->
<!--                          size="small"></el-date-picker>-->

            <el-date-picker
                v-model="searchForm.year"
                type="year"
                size="small"
                placeholder="离职年份"
                value-format="yyyy">
            </el-date-picker>
          <el-button type="primary" size="small" @click="searchFn('search')"><i class="el-icon-search"></i>搜索
          </el-button>
          <el-button size="small" @click="searchFn('refresh')"><i class="el-icon-refresh"></i>重置刷新</el-button>
          <downexcel type="tearchHistory"></downexcel>
          <span class="numberline toplineBox-right">总{{ page.total }}条</span>
        </div>
        <el-table
            border
            ref="multipleTable"
            :data="arryList"
            :stripe="tableStripe"
            :border="tableBorder"
            :height="tableHeight"
            tooltip-effect="dark">
          <el-table-column
              align="center"
              prop="account"
              label="账户名"
              width="110">
          </el-table-column>
          <el-table-column
              align="center"
              prop="realname"
              label="姓名"
              width="100">
          </el-table-column>
          <el-table-column
              label="头像"
              width="80"
              align="center">
            <template slot-scope="scope">
              <viewerModle type="1" :imgSrc="scope.row.pic"></viewerModle>
            </template>
          </el-table-column>
          <el-table-column
              align="center"
              prop="section_name"
              label="年段">
            <template slot-scope="scope">
              <span v-if="!scope.row.section" class="notborrow">未定义</span>
              <span v-else>{{ scope.row.section.section_name }}</span>
            </template>
          </el-table-column>
          <el-table-column
              prop="class_name"
              label="班级"
              align="center">
            <template slot-scope="scope">
              <span v-if="!scope.row.classes" class="notborrow">未定义</span>
              <span v-else>{{ scope.row.classes.class_name }}</span>
            </template>
          </el-table-column>
          <el-table-column
              prop="role"
              label="角色"
              align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.role">{{ scope.row.role.name }}</span>
              <span v-else class="notborrow">未定义</span>
            </template>
          </el-table-column>
          <el-table-column
              prop="create_time"
              label="入职时间"
              align="center"></el-table-column>
          <el-table-column
              prop="update_time"
              label="离职时间"
              align="center"></el-table-column>
        </el-table>
        <!--工具条 分页-->
        <el-col :span="24" class="toolbar">
          <el-pagination
              background
              :page-size="page.pagesize"
              :current-page="page.pageindex"
              layout="total, prev, pager, next"
              :total="page.total"
              @current-change="handleSizeChange"></el-pagination>
        </el-col>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {pagination, yearDay} from '@/utils/util.js'

export default {
  props: ['visible', 'materielOption'], // commoent 学生点评 collection 学生采集
  components: {},
  data() {
    return {
      dialogVisible: false,
      yeartimeFn: yearDay,
      tableStripe: true, // 是否斑马栏
      tableBorder: true, // 单元格右边边框
      arryList: [], // 数据列表
      // 页数
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      searchForm: {
        realname: '',
        role: '',
        year: ''
      }, // 编辑界面数据
      pickerOptions1:
          {
            disabledDate(time) {
              return time.getTime() > Date.now() // - 8.64e7
            }
          },
      tableHeight: 0,
      role: []
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (this.visible) {
        let n = this;
        this.$nextTick(() => {
          let height = n.$refs.dialogBox.offsetHeight;  //top 50 1 search 50 page 50 10 footer 50 1
          this.tableHeight = height - (51 + 43 + 50 + 20 + 51)
          console.log('height:', height)
        })
        this.InitFn()
        this.roleFn()
      } else {
        this.arryList = [];
      }
    }
  },
  created() {
  },
  methods: {
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    // 初始化
    async InitFn() {
      this.searchForm.p = this.page.pageindex;
      let data = await this.$fetch(this.api.admin_recyclebin, this.searchForm);
      if (!data.code) {
        for (let i in data.list.data) {
          data.list.data[i].update_time = yearDay(data.list.data[i].update_time)
        }
        this.arryList = data.list.data
        this.page.total = data.list.total
      } else {
      }
    },
    // 搜索组件
    searchFn(option) {
      if (option === 'refresh') {
        this.searchForm.realname = ''
        this.searchForm.role = ''
        this.searchForm.year = ''
      }
      this.page.pageindex = 1
      this.InitFn()
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
    // 角色
    async roleFn() {
      let data = await this.$post(this.api.role.select, {});
      if (!data.code) {
        for (let i in data.list) {
          this.role.push(data.list[i])
        }
      }
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 80%;
  height: 75%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

</style>


